﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Lawyer.Web.Admin
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        public string UserName = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.Url.AbsolutePath.Substring(7);

            LoadRootNav(url);
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            CheckSession();
        }

        private void CheckSession()
        {
            if ((Session["UserName"] != null) && (Session["Type"].ToString().Equals("1")))
            {
                UserName = Session["UserName"].ToString();
            }
            else
            {
                string rtn = Request.Url.AbsolutePath;
                Response.Redirect("../login.aspx?rtn=" + rtn);
            }
        }

        private void LoadRootNav(string url)
        {
            Hashtable navlist = new Hashtable();
            navlist.Add("admin_dashboard.aspx", "admin_dashboard");
            navlist.Add("admin_postlist.aspx", "admin_dashboard");

            navlist.Add("admin_archivelist.aspx", "admin_archivelist");
            navlist.Add("admin_archiveadd.aspx", "admin_archivelist");
            navlist.Add("admin_activity.aspx", "admin_activity");

            navlist.Add("admin_archivelist.aspx?status=0", "admin_archivelist");
            navlist.Add("admin_archivelist.aspx?status=1", "admin_archivelist");
            navlist.Add("admin_archivelist.aspx?status=2", "admin_archivelist");
            navlist.Add("admin_archivelist.aspx?status=3", "admin_archivelist");
            navlist.Add("admin_archivelist.aspx?status=4", "admin_archivelist");

            navlist.Add("admin_activityadd.aspx", "admin_activity");
            navlist.Add("admin_activity.aspx?status=1", "admin_activity");
            navlist.Add("admin_activity.aspx?status=2", "admin_activity");
            navlist.Add("admin_activity.aspx?status=3", "admin_activity");
            navlist.Add("admin_activity.aspx?status=4", "admin_activity");
            navlist.Add("admin_activitytype.aspx", "admin_activity");

            navlist.Add("admin_userlist.aspx", "admin_userlist");
            navlist.Add("admin_useradd.aspx", "admin_userlist");

            navlist.Add("admin_agencyadd.aspx", "admin_agencylist");
            navlist.Add("admin_agencylist.aspx", "admin_agencylist");

            navlist.Add("admin_password.aspx", "admin_password");
                
            //navlist.Add("admin_customadd.aspx", "customlist");
            //  navlist.Add("contacts.aspx", "customlist");


            if (url != null)
            {
                string item = "";
                foreach (DictionaryEntry de in navlist)
                {
                    if (de.Key.ToString().Equals(url))
                    {
                        item = de.Value.ToString();
                    }
                }

                ScriptManager.RegisterStartupScript(this, this.GetType(), "keyname", "LoadPageNav('" + item + "');", true);
            }

        }
    }
}
